package driver

type Handle interface {
	EnableFileTransport() error
	Mkdir(dir string) error
	PushFile(local, remote string) error
	UnTarGZ(file, to string) error
	UnTar(file, to string) error
	RmFile(file string) error
	AddExe(file string) error
	WriteFile(file string, content []byte) error
	ReadFile(file string) ([]byte, error)
	IsExist(file string) (bool, error)
	Ln(to, from string) error

	Execute(cmd string) (string, error)
	Close() error
}

type Driver interface {
	CreateHandle() Handle
}

type driver_slot struct {
	create  func(string, int, string) Driver
	destroy func(Driver)
}

var driver_set map[string]driver_slot = make(map[string]driver_slot)

func Create(driver_name, host string, port int, args string) Driver {
	v, ok := driver_set[driver_name]
	if !ok {
		return nil
	}

	return v.create(host, port, args)
}

func Destroy(driver_name string, driver Driver) {
	v, ok := driver_set[driver_name]
	if !ok {
		return
	}

	v.destroy(driver)
}
